import LevelInitBase from "../LevelCommon/LevelInitBase";
import LevelControl7 from "../LevelControl/LevelControl7";
import RoomControl from "../LevelCommon/RoomControl";
import { utils } from "../../utils/CommonUtil";
import FocusParentObj from "../Prefabs/InteractivObj/Common/FocusParentObj";
import GamePropObj from "../Prefabs/InteractivObj/Common/GamePropObj";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import CallToLevel from "../Prefabs/CallToLevel";
import PhysPassLock from "../Prefabs/InteractivObj/PhysPassLock/PhysPassLock";
import PhysPassKey from "../Prefabs/InteractivObj/PhysPassLock/PhysPassKey";
import SparkPlugLockKey from "../Prefabs/InteractivObj/SparkPlugBox/SparkPlugLockKey";
import SparkPlugLock from "../Prefabs/InteractivObj/SparkPlugBox/SparkPlugLock";
import Gate from "../Prefabs/InteractivObj/Gate";
import EnumData from "../../Enum/EnumData";
import SparkPlugBox from "../Prefabs/InteractivObj/SparkPlugBox/SparkPlugBox";
import MoveLock from "../Prefabs/InteractivObj/MoveLock/MoveLock";
import MoveLockKey from "../Prefabs/InteractivObj/MoveLock/MoveLockKey";
import GamePropConst from "../../constant/GamePropConst";
import SparkPlug from "../Prefabs/InteractivObj/SparkPlugBox/SparkPlug";

export default class LevelInit7 extends LevelInitBase {
    private room1: Laya.Sprite3D;
    private room2: Laya.Sprite3D;
    private room3: Laya.Sprite3D;
    private room4: Laya.Sprite3D;

    private container: Laya.Sprite3D;

    public startInitDetail() {
        this.levelRoot.addComponent(LevelControl7);
        this.room1 = this.LevelObjs.getChildByName("room1") as Laya.Sprite3D;
        this.room1.addComponent(RoomControl);
        this.room2 = this.LevelObjs.getChildByName("room2") as Laya.Sprite3D;
        this.room2.addComponent(RoomControl);
        this.room3 = this.LevelObjs.getChildByName("room3") as Laya.Sprite3D;
        this.room3.addComponent(RoomControl);
        this.room4 = this.LevelObjs.getChildByName("room4") as Laya.Sprite3D;
        this.room4.addComponent(RoomControl);
        this.container = this.room1.getChildByName("Container") as Laya.Sprite3D;

        //#region room1 wall1
        let room1Walls = this.room1.getChildByName("walls");
        let room1Wall1 = room1Walls.getChildByName("wall1");

        let bookcase_1 = room1Wall1.getChildByName("bookcase_1");
        utils.CommonUtils.CustomAddComponent(bookcase_1, FocusParentObj);

        let book_01_props = bookcase_1.getChildByName("book_01_props");
        let GamePropObj_book_01_props = utils.CommonUtils.CustomAddComponent(book_01_props, GamePropObj) as GamePropObj;
        GamePropObj_book_01_props.gamePropId = 33;

        let bookcase_2 = room1Wall1.getChildByName("bookcase_2");
        let MoveObj_bookcase_2 = utils.CommonUtils.CustomAddComponent(bookcase_2, MoveObj) as MoveObj;
        MoveObj_bookcase_2.targetPos = new Laya.Vector3(0.36176, -9, -1.93);
        MoveObj_bookcase_2.VoiceName = "move";

        let Trapezoidal_key = room1Wall1.getChildByName("Trapezoidal key");
        let GamePropObj_Trapezoidal_key = utils.CommonUtils.CustomAddComponent(Trapezoidal_key, GamePropObj) as GamePropObj;
        GamePropObj_Trapezoidal_key.gamePropId = 35;

        let room1_rom2Gate = room1Wall1.getChildByName("room1-rom2Gate");
        utils.CommonUtils.CustomAddComponent(room1_rom2Gate, CallToLevel);

        //#endregion

        //#region room1 wall2
        let room1Wall2 = room1Walls.getChildByName("wall2");
        let painting = room1Wall2.getChildByName("painting");
        utils.CommonUtils.CustomAddComponent(painting, FocusParentObj);

        let password_BOXParent = room1Wall2.getChildByName("password BOX");
        utils.CommonUtils.CustomAddComponent(password_BOXParent, FocusParentObj);

        let password_BOX = password_BOXParent.getChildByName("password BOX");
        let PhysPassLock_password_BOX = utils.CommonUtils.CustomAddComponent(password_BOX, PhysPassLock) as PhysPassLock;
        PhysPassLock_password_BOX.correctPassInde.push(4);
        PhysPassLock_password_BOX.correctPassInde.push(5);
        PhysPassLock_password_BOX.correctPassInde.push(6);

        for (let index = 0; index < password_BOX.numChildren; index++) {
            let passwordObj = password_BOX.getChildAt(index);
            let PhysPassKey_passwordObj = utils.CommonUtils.CustomAddComponent(passwordObj, PhysPassKey) as PhysPassKey;
            PhysPassKey_passwordObj.isRotateY = true;
            PhysPassKey_passwordObj.rotateAngle = -45;
        }

        let sparkLockKey4 = room1Wall2.getChildByName("sparkLockKey4");
        utils.CommonUtils.CustomAddComponent(sparkLockKey4, FocusParentObj);

        let rhombus = sparkLockKey4.getChildByName("rhombus");
        let SparlPlugLockKey_rhombus = utils.CommonUtils.CustomAddComponent(rhombus, SparkPlugLockKey) as SparkPlugLockKey;
        SparlPlugLockKey_rhombus.curNeedPlugId = 37;

        let Triangle = room1Wall2.getChildByName("Triangle");
        utils.CommonUtils.CustomAddComponent(Triangle, FocusParentObj);

        let sparkLockKey3 = room1Wall2.getChildByName("sparkLockKey3");
        utils.CommonUtils.CustomAddComponent(sparkLockKey3, FocusParentObj);

        let Trapezoid = sparkLockKey3.getChildByName("Trapezoid");
        let SparkPlugLockKey_Trapezoid = utils.CommonUtils.CustomAddComponent(Trapezoid, SparkPlugLockKey) as SparkPlugLockKey;
        SparkPlugLockKey_Trapezoid.curNeedPlugId = 35;

        //#endregion

        //#region room1 wall3
        let room1Wall3 = room1Walls.getChildByName("wall3");
        let endGate1 = room1Wall3.getChildByName("endGate1");
        let Gate_endGate1 = utils.CommonUtils.CustomAddComponent(endGate1, Gate) as Gate;
        Gate_endGate1.needPropId = 1111111;
        Gate_endGate1.Axis = EnumData.Axis.Z;
        Gate_endGate1.Angle = -30;

        // let endGate2 = room1Wall3.getChildByName("endGate2");
        // let Gate_endGate2 = utils.CommonUtils.CustomAddComponent(endGate2, Gate) as Gate;
        // Gate_endGate2.needPropId = 1111111;
        // Gate_endGate2.Axis = EnumData.Axis.X;
        // Gate_endGate2.Angle = -120;
        //#endregion

        //#region room1Wall4
        let room1Wall4 = room1Walls.getChildByName("wall4");

        let sparkLockKey1 = room1Wall4.getChildByName("sparkLockKey1");
        utils.CommonUtils.CustomAddComponent(sparkLockKey1, FocusParentObj);
        let Round = sparkLockKey1.getChildByName("Round");
        let SparkPlugLockKey_Round = utils.CommonUtils.CustomAddComponent(Round, SparkPlugLockKey) as SparkPlugLockKey;
        SparkPlugLockKey_Round.curNeedPlugId = 36;

        let sparkLockKey2 = room1Wall4.getChildByName("sparkLockKey2");
        utils.CommonUtils.CustomAddComponent(sparkLockKey2, FocusParentObj);
        let Square = sparkLockKey2.getChildByName("Square");
        let SparkPlugLockKey_Square = utils.CommonUtils.CustomAddComponent(Square, SparkPlugLockKey) as SparkPlugLockKey;
        SparkPlugLockKey_Square.curNeedPlugId = 34;

        let Cone = room1Wall4.getChildByName("Cone");
        utils.CommonUtils.CustomAddComponent(Cone, FocusParentObj);

        //#endregion
        let SparkPlugLockObj = this.room1.getChildByName("Container").getChildByName("SparkPlugLock");
        let SparkPlugLock_SparkPlugLock = utils.CommonUtils.CustomAddComponent(SparkPlugLockObj, SparkPlugLock) as SparkPlugLock;
        SparkPlugLock_SparkPlugLock.lockKeys.push(SparkPlugLockKey_Round);
        SparkPlugLock_SparkPlugLock.lockKeys.push(SparkPlugLockKey_Square);
        SparkPlugLock_SparkPlugLock.lockKeys.push(SparkPlugLockKey_Trapezoid);
        SparkPlugLock_SparkPlugLock.lockKeys.push(SparlPlugLockKey_rhombus);

        let jinianpin1 = this.room1.getChildByName("jinianpin (1)");
        let GamePropObj_jinianpin1 = utils.CommonUtils.CustomAddComponent(jinianpin1, GamePropObj) as GamePropObj;
        GamePropObj_jinianpin1.gamePropId = 11;

        let jinianpin2 = this.room1.getChildByName("jinianpin (2)");
        let GamePropObj_jinianpin2 = utils.CommonUtils.CustomAddComponent(jinianpin2, GamePropObj) as GamePropObj;
        GamePropObj_jinianpin2.gamePropId = 11;

        //#region room2

        let room2Walls = this.room2.getChildByName("walls");
        let room2Wall1 = room2Walls.getChildByName("wall1");

        let room2_room3_Gate1 = room2Wall1.getChildByName("room2_room3_Gate1");
        let Gate_room2_room3_Gate1 = utils.CommonUtils.CustomAddComponent(room2_room3_Gate1, Gate) as Gate;
        Gate_room2_room3_Gate1.Axis = EnumData.Axis.X;
        Gate_room2_room3_Gate1.Angle = -30;
        Gate_room2_room3_Gate1.needPropId = 1111111111;
        Gate_room2_room3_Gate1.isOpen = true;

        let room2_room3_Gate2 = room2Wall1.getChildByName("room2_room3_Gate2");
        let Gate_room2_room3_Gate2 = utils.CommonUtils.CustomAddComponent(room2_room3_Gate2, Gate) as Gate;
        Gate_room2_room3_Gate2.Axis = EnumData.Axis.X;
        Gate_room2_room3_Gate2.Angle = -30;
        Gate_room2_room3_Gate2.needPropId = 1111111111;

        let sparkPlugBoxParent = room2Wall1.getChildByName("sparkPlugBox");
        utils.CommonUtils.CustomAddComponent(sparkPlugBoxParent, FocusParentObj);

        let sparkPlugBox = sparkPlugBoxParent.getChildByName("sparkPlugBox");
        let SparkPlugBox_sparkPlugBox = utils.CommonUtils.CustomAddComponent(sparkPlugBox, SparkPlugBox) as SparkPlugBox;
        SparkPlugBox_sparkPlugBox.GateName = "room2_room3_Gate2";
        SparkPlugBox_sparkPlugBox.needPropId = 36;

        let room2_room1Gate = room2Walls.getChildByName("wall3").getChildByName("room2_room1Gate");
        utils.CommonUtils.CustomAddComponent(room2_room1Gate, CallToLevel);

        //#endregion

        //#region room3
        let room3Walls = this.room3.getChildByName("walls");
        let room3Wall1 = room3Walls.getChildByName("wall1");

        let room3_room4_Gate = room3Wall1.getChildByName("room3_room4_Gate");
        let Gate_room3_room4_Gate = utils.CommonUtils.CustomAddComponent(room3_room4_Gate, Gate) as Gate;
        Gate_room3_room4_Gate.Axis = EnumData.Axis.Y;
        Gate_room3_room4_Gate.Angle = 10;
        Gate_room3_room4_Gate.needPropId = 1111111;

        let sparkPlugBoxParent2 = room3Wall1.getChildByName("sparkPlugBox");
        utils.CommonUtils.CustomAddComponent(sparkPlugBoxParent2, FocusParentObj);
        let sparkPlugBox2 = sparkPlugBoxParent2.getChildByName("sparkPlugBox");
        let SparkPlugBox_sparkPlugBox2 = utils.CommonUtils.CustomAddComponent(sparkPlugBox2, SparkPlugBox) as SparkPlugBox;
        SparkPlugBox_sparkPlugBox2.GateName = "room3_room4_Gate";
        SparkPlugBox_sparkPlugBox2.needPropId = 37;

        let tuan = room3Wall1.getChildByName("tuan");
        utils.CommonUtils.CustomAddComponent(tuan, FocusParentObj);

        let room3Wall3 = room3Walls.getChildByName("wall3");
        let room3_room2_Gate2 = room3Wall3.getChildByName("room3_room2_Gate2");
        let Gate_room3_room2_Gate2 = utils.CommonUtils.CustomAddComponent(room3_room2_Gate2, Gate) as Gate;
        Gate_room3_room2_Gate2.Axis = EnumData.Axis.Y;
        Gate_room3_room2_Gate2.Angle = 10;
        Gate_room3_room2_Gate2.needPropId = 1111111;

        let room3_room2_Gate1 = room3Wall3.getChildByName("room3_room2_Gate1");
        let Gate_room3_room2_Gate1 = utils.CommonUtils.CustomAddComponent(room3_room2_Gate1, Gate) as Gate;
        Gate_room3_room2_Gate1.Axis = EnumData.Axis.Y;
        Gate_room3_room2_Gate1.Angle = 10;
        Gate_room3_room2_Gate1.needPropId = 2147483647;
        Gate_room3_room2_Gate1.isOpen = true;

        let sparkPlugBoxParent3 = room3Wall3.getChildByName("sparkPlugBox");
        utils.CommonUtils.CustomAddComponent(sparkPlugBoxParent3, FocusParentObj);
        let sparkPlugBox3 = sparkPlugBoxParent3.getChildByName("sparkPlugBox");
        let SparkPlugBox_sparkPlugBox3 = utils.CommonUtils.CustomAddComponent(sparkPlugBox3, SparkPlugBox) as SparkPlugBox;
        SparkPlugBox_sparkPlugBox3.GateName = "room3_room2_Gate1";
        SparkPlugBox_sparkPlugBox3.needPropId = 37;

        let spark_plug_37 = sparkPlugBox3.getChildByName("sparkPos").getChildByName("spark_plug_37");
        let SparkPlug_spark_plug_37 = utils.CommonUtils.CustomAddComponent(spark_plug_37,SparkPlug) as SparkPlug;
        SparkPlug_spark_plug_37.gamePropId = 37;
        SparkPlug_spark_plug_37.curSparkBox = SparkPlugBox_sparkPlugBox3;
        //#endregion

        //#region Room4
        let room4Walls = this.room4.getChildByName("walls");
        let room4wall2 = room4Walls.getChildByName("wall2");

        let chouti = room4wall2.getChildByName("Drawer").getChildByName("chouti");
        let moveObj_chouti = utils.CommonUtils.CustomAddComponent(chouti, MoveObj) as MoveObj;
        moveObj_chouti.targetPos = new Laya.Vector3(0, 0, 0.8);
        let chouti_props = chouti.getChildByName("chouti_props");
        utils.CommonUtils.CustomAddComponent(chouti_props, FocusParentObj);

        let MoveLockObj = chouti_props.getChildByName("MoveLock");
        let movePoses = MoveLockObj.getChildByName("movePoses");
        let MoveLock_MoveLockObj = utils.CommonUtils.CustomAddComponent(MoveLockObj, MoveLock) as MoveLock;
        for (let index = 0; index < movePoses.numChildren; index++) {
            MoveLock_MoveLockObj.curAllPoses.push((movePoses.getChildAt(index) as Laya.Sprite3D).transform);
            MoveLock_MoveLockObj.correctIndex.push(index);
            let moveLockKeyObj = MoveLockObj.getChildAt(index);
            let MoveLockKey_moveLockKeyObj = utils.CommonUtils.CustomAddComponent(moveLockKeyObj, MoveLockKey) as MoveLockKey
            switch (index) {
                case 0:
                    MoveLockKey_moveLockKeyObj.curPosIndex = 2;
                    break;
                case 1:
                    MoveLockKey_moveLockKeyObj.curPosIndex = 3;
                    break;
                case 2:
                    MoveLockKey_moveLockKeyObj.curPosIndex = 1;
                    break;
                case 3:
                    MoveLockKey_moveLockKeyObj.curPosIndex = 0;
                    break;
            }
        }

        let Square_key001 = chouti_props.getChildByName("Square key001");
        let GamePropObj_Square_key001 = utils.CommonUtils.CustomAddComponent(Square_key001, GamePropObj) as GamePropObj;
        GamePropObj_Square_key001.gamePropId = 36;

        let room4wall3 = room4Walls.getChildByName("wall3");
        let room4_room3_Gate = room4wall3.getChildByName("room4_room3_Gate");
        let Gate_room4_room3_Gate = utils.CommonUtils.CustomAddComponent(room4_room3_Gate, Gate) as Gate;
        Gate_room4_room3_Gate.needPropId = 2147483647;
        Gate_room4_room3_Gate.Angle = 10;
        Gate_room4_room3_Gate.Axis = EnumData.Axis.Y;

        let jinianpin = this.room4.getChildByName("jinianpin");
        let GamePropObj_jinianpin = utils.CommonUtils.CustomAddComponent(jinianpin, GamePropObj) as GamePropObj;
        GamePropObj_jinianpin.gamePropId = 11;

        //#endregion
    }
}